package com.entrogy.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 静态图片资源映射
 * @author xlr
 * @date 2019.6.19
 */

@ComponentScan
@Configuration
public class PhotoConfig extends WebMvcConfigurerAdapter {

    private static final Logger logger = LoggerFactory.getLogger(PhotoConfig.class);

    @Value("${upload.imagesPath}")
    private String myImagePath;
    @Value("${show.image.url}")
    private String imageUrl;
    /*
     * 注册静态文件的自定义映射路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //定义到硬盘
        registry.addResourceHandler("/"+imageUrl+"/**")
                .addResourceLocations(myImagePath);
        super.addResourceHandlers(registry);
    }
}
